package cn.iocoder.yudao.module.brokerage.level.service;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.service.impl.BaseService;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.brokerage.level.dao.BrokerageLevelMapper;
import cn.iocoder.yudao.module.brokerage.level.pojo.po.BrokerageLevelDO;
import cn.iocoder.yudao.module.brokerage.level.pojo.vo.AdminBrokerageLevelQueryDTO;
import cn.iocoder.yudao.module.brokerage.level.pojo.vo.AdminBrokerageLevelSaveDTO;
import cn.iocoder.yudao.module.brokerage.level.pojo.vo.AdminBrokerageLevelVO;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * 推广人员等级 Service 实现类
 *
 * @author 山野羡民
 */
@Service
@Validated
public class AdminBrokerageLevelServiceImpl extends BaseService<BrokerageLevelDO, AdminBrokerageLevelVO, AdminBrokerageLevelQueryDTO> implements AdminBrokerageLevelService {
    @Resource
    private BrokerageLevelMapper brokerageLevelMapper;

    @Override
    protected BrokerageLevelMapper getInjectedMapper() {
        return brokerageLevelMapper;
    }

    @Nonnull
    @Override
    protected CoreQueryWrapper<BrokerageLevelDO> buildQueryWrapper(AdminBrokerageLevelQueryDTO param) {
        CoreQueryWrapper<BrokerageLevelDO> wrapper = super.buildQueryWrapper(param);
        wrapper.eqIfPresent("type", param.getType());
        wrapper.orderByAsc("type");
        wrapper.orderByAsc("weight");
        return wrapper;
    }

    @Override
    public boolean update(AdminBrokerageLevelSaveDTO param, Long userId) {
        BrokerageLevelDO entity = validateExists(param.getId());
        BrokerageLevelDO updateObj = BeanUtils.toBean(param, BrokerageLevelDO.class);
        updateObj.setId(entity.getId());
        int ret = getInjectedMapper().updateById(updateObj);
        return SqlHelper.retBool(ret);
    }

}